class GameObject
{
  PVector position;
  int mass;
  PVector velocity;
  boolean drawn;
  boolean alive;
 
  GameObject(int xin, int yin, int massin)
  {
    position = new PVector(xin, yin);
    mass = massin;
    velocity = new PVector(0,0,0);
    drawn = true;
    alive = true;
  }
  GameObject(int xin, int yin, int massin, PVector vin)
  {
    position = new PVector(xin, yin);
    mass = massin;
    velocity = vin;
    drawn = true;
    alive = true;
  }
  
  void updatePosition()
  {
    position.add(velocity);
  }
  
  void checkCollisions()
  {

  }
  
  void applyPlanetGravity()
  {
    PVector acceleration = new PVector(0,0,0);//this vector represents the acceleration to be applied to the velocity of the ship  
    for(int i =0; i < planetCount; i++)
    {
      Planet planet = (Planet)planets.get(i);
      float force = planet.mass*this.mass/sq(sqrt(sq(planet.position.x - position.x) + sq(planet.position.y - position.y)));
      float distance = sqrt(sq(planet.position.x - position.x) + sq(planet.position.y - position.y));
      float forceX = (force*(planet.position.x - position.x))/distance;
      float forceY = (force*(planet.position.y-position.y))/distance;
      acceleration.set(forceX/this.mass,forceY/this.mass,0);
      this.velocity.add(acceleration);    
    } 
  }
  
  void applyPlanetGravity(Planet planet)
  {
    PVector acceleration = new PVector(0,0,0);//this vector represents the acceleration to be applied to the velocity of the ship  
      float force = planet.mass*this.mass/sq(sqrt(sq(planet.position.x - position.x) + sq(planet.position.y - position.y)));
      float distance = sqrt(sq(planet.position.x - position.x) + sq(planet.position.y - position.y));
      float forceX = (force*(planet.position.x - position.x))/distance;
      float forceY = (force*(planet.position.y-position.y))/distance;
      acceleration.set(forceX/this.mass,forceY/this.mass,0);
      this.velocity.add(acceleration);     
  }
  
  void applyPlayerGravity(Player aPlayer)
  {
    if(player.alive)
    {
    if(!(player.grav == 0))
      {
        PVector acceleration = new PVector(0,0,0); 
        float force = 4*player.grav*aPlayer.mass*this.mass/sq(sqrt(sq(aPlayer.position.x - position.x) + sq(aPlayer.position.y - position.y)));//added in *player.grav to the nominator to make the grav work in the right directions
        float distance = sqrt(sq(aPlayer.position.x - position.x) + sq(aPlayer.position.y - position.y));
        float forceX = (force*(aPlayer.position.x - position.x))/distance;
        float forceY = (force*(aPlayer.position.y-position.y))/distance;
        acceleration.set(forceX/this.mass,forceY/this.mass,0);
        this.velocity.add(acceleration); 
      }
    }
  }
  
  void update()
  {
    updatePosition();
    applyPlanetGravity();
    checkCollisions();
  }

  
  //Draw based on camera position
  void draw(Camera c)
  {
    
  }
  
  
}
